﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using xplang.fs;
using xplang.errors;
using System.Diagnostics;

namespace xplang.parse
{
  public enum TokenType
  {
    ttError,
    ttInternal,
    ttEOF,
    ttStringSingle,
    ttStringDouble,
    ttIntNumber,
    ttDecNumber,
    ttClause,
    ttIdentifier,
    ttFunction,
    ttSpace,
    ttComment,
    ttOperator
  }

  [DebuggerDisplay("{type}=\"{text}\" pos:{start} len:{length} prec:{prec}")]
  public class Token
  {
    public const int PreOperator = 1001;
    public const int PostOperator = 1002;
    public const int PreOrPostOperator = 1003;
    public Token(SourceCode sourceCode, int start, int length, int prec, TokenType type, String text)
    {
      this.sourceCode = sourceCode;
      this.start = start;
      this.length = length;
      this.type = type;
      this.text = text;
      this.prec = prec;
    }

    public Token(String text)
    {
      this.sourceCode = null;
      this.start = 0;
      this.length = 0;
      this.type = TokenType.ttInternal;
      this.text = text;
      this.prec = -1;
    }

    public SourceCode sourceCode;
    public int start;
    public int length;
    public int prec;
    public TokenType type;
    public String text;

    public static bool isClause(string word)
    {
      return
          "|if|else|while|switch|case|void|return|for|static|public|private|protected|sealed|readonly|".
          IndexOf("|" + word + "|") > 0;
    }

    public static bool isOperator(string word)
    {
      return
          "|in|is|".
          IndexOf("|" + word + "|") > 0;
    }

  }
}
